
{extend name="public:common_edit"/}
{block name="css"}
<style>
    .form-control {
        max-width: 350px;
    }

    .tb-name {
        width: 238px;
    }
    .error{
        color: red;
        margin-top: 10px;
        display: none;
    }
    .select{
        margin-bottom: 10px;
    }
    .doctor{
        display: none;
    }
</style>
{/block}
{block name="main"}
<section class="content">
    <div class="container-fluid">
        <div class="pull-right">
            <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default"
               data-original-title="返回"><i class="fa fa-reply"></i></a>
            <a href="javascript:void(0);" class="btn btn-default"
               data-url="javascript:;"
               onclick="get_help(this)"><i class="fa fa-question-circle"></i> 帮助</a>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-list"></i> {$title}</h3>
            </div>
            <div class="panel-body">
                <!--表单数据-->
                <form action="" method="post" class="form-horizontal"
                      id="category_form">

                    <!--通用信息-->
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab_tongyong">
                            <table class="table table-bordered">
                                <tbody>
                                <tr>
                                    <td>类型</td>
                                    <td>
                                        {if $data.type == 1}
                                            安卓
                                        {else/}
                                            苹果
                                        {/if}
                                    </td>
                                </tr>

                                <tr>
                                    <td>{if $data.type == 1}版本号:{else/}正式版  版本号:{/if}</td>
                                    <td><input placeholder="版本号" class="form-control" name="versionCode" type="text" value="{$data.versionCode}"></td>
                                </tr>
                                <tr>
                                    <td>{if $data.type == 1}版本名:{else/}测试版本 版本号:{/if}:</td>
                                    <td><input placeholder="版本名" class="form-control" name="versionName" type="text" value="{$data.versionName}"></td>
                                </tr>
                                {if $data.type == 2}
                                <tr>
                                    <td>安装包是否在审核中:</td>
                                    <td>
                                        <select class="form-control" name="pg_zzsh">
                                            <option id="pg_zzsh1" value="1">是</option>
                                            <option id="pg_zzsh0" value="0">否</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>是否需要展示ios日志:</td>
                                    <td>
                                        <select class="form-control" name="pg_xsrz">
                                            <option id="pg_xsrz1" value="1">是</option>
                                            <option id="pg_xsrz0" value="0">否</option>
                                        </select>
                                    </td>
                                </tr>

                                {/if}
                                <tr>
                                    <td>链接地址:</td>
                                    <td><input placeholder="链接地址" class="form-control" name="url" type="text" value="{$data.url}"></td>
                                </tr>
                                <tr>
                                    <td>安装包上传:</td>
                                    <td><input id="file"  class="file-container" style="float: left"  type="file" value="安装包上传"><span class="btn btn-primary qiniu">点击上传安装包</span></td>
                                </tr>
                                <tr>
                                    <td>更新内容:</td>
                                    <td><textarea name="detail" id="" cols="30" rows="10">{$data.detail}</textarea></td>
                                </tr>
                                <tr>
                                    <td>强制更新:</td>
                                    <td>
                                        <select class="form-control" name="force">
                                            <option id="force1" value="1">是</option>
                                            <option id="force0" value="0">否</option>
                                        </select>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="pull-right">
                        <label class="control-label col-sm-2"></label>
                        <input type="hidden" name="id" value="{$data.id}">
                        <input class="btn btn-primary submit" type="submit" value="保存">
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
{/block}
{block name="js"}
<script type="text/javascript" src="https://unpkg.com/qiniu-js@v2.4.0/dist/qiniu.min.js"></script>
<script>
    $('.qiniu').click(function () {
        var file = $('#file')[0].files[0];
        if (!file){
            layer.msg('您未选择文件', {icon: 5, time: 2000});return false;
        }
        var btn = $(this);
        btn.attr('disabled', 'disabled');
        layer.msg('上传中', {
            icon: 16
            ,shade: [0.3,'#999999'],
            time:21600000
        });
        var token = "{$token}";
        var index = file.name.lastIndexOf(".");
        var ext = file.name.substring(index);
        var key = takeName('vod',2)+ext;
        var config = {
            useCdnDomain: true,
            region: qiniu.region.z0,
            concurrentRequestLimit:3,
        };
        var putExtra = {
            fname: file.name,
            params: {},
            mimeType:  null
        };
        var observer = {
            next(res){
                $('.layui-layer-padding').html('<i class="layui-layer-ico layui-layer-ico16"></i>上传中 '+res.total.percent.toFixed(2)+'%');
            },
            error(err){
                layer.msg('上传失败,请稍后重试'+err.message, {icon: 5, time: 2000});
                layer.closeAll("loading");
                btn.attr('disabled', false);
            },
            complete(res){
                var domain = "{$domain}";
                var url = domain+'/'+res.key;
                $("input[name='url']").val(url);
                layer.msg('上传成功', {icon: 1, time: 2000});
                layer.closeAll("loading");
                btn.attr('disabled', false);
                removeFile('file');
            }
        };
        var observable = qiniu.upload(file, key, token, putExtra, config)
        var subscription = observable.subscribe(observer)

    });
    $(function () {
        var force   = "{$data.force}";
        if(force != ''){
            $('#force'+force).attr('selected',true)
        }

        var pg_xsrz   = "{$data.pg_xsrz}";
        if(pg_xsrz != ''){
            $('#pg_xsrz'+pg_xsrz).attr('selected',true)
        }

        var pg_zzsh   = "{$data.pg_zzsh}";
        if(pg_zzsh != ''){
            $('#pg_zzsh'+pg_zzsh).attr('selected',true)
        }

    })

</script>



{/block}